package com.inspire.myapp;

import com.codename1.io.Preferences;
import com.codename1.io.Storage;
import com.codename1.ui.Button;
import com.codename1.ui.Component;
import com.codename1.ui.Container;
import com.codename1.ui.Display;
import com.codename1.ui.Label;
import com.codename1.ui.TextField;
import com.codename1.ui.events.ActionEvent;
import com.codename1.ui.events.ActionListener;
import com.codename1.ui.events.DataChangedListener;
import com.codename1.ui.layouts.BoxLayout;
import com.codename1.ui.layouts.Layout;
import com.codename1.ui.util.UIBuilder;

public class menutab_reglage extends Container {

	public menutab_reglage() {
		
		//utils.setBackground(tab3,imgback);
		BoxLayout tab3l=new BoxLayout(BoxLayout.Y_AXIS);
		this.setLayout(tab3l);
		this.setScrollableY(true);
		this.addComponent(new Label("Url du NAS"));
		String urlnas=Preferences.get("URL_NAS", objets.httpdefault);
		final TextField tt=new TextField(urlnas);
		this.addComponent(tt);
		tt.addDataChangeListener(new DataChangedListener() {
			@Override
			public void dataChanged(int type, int index) {
				Preferences.set("URL_NAS", tt.getText());
			}
		});

		this.addComponent(new Label("Application externe URL"));
		String critere1=Preferences.get("URL_appliexterne", "http://www.google.com");
		final TextField tt1=new TextField(critere1);
		this.addComponent(tt1);
		tt1.addDataChangeListener(new DataChangedListener() {
			@Override
			public void dataChanged(int type, int index) {
				Preferences.set("URL_appliexterne", tt1.getText());
			}
		});
		Button bb=new Button("test appli externe");
		bb.getStyle().setPadding(15, 15, 10, 10);
		bb.setAlignment(Component.RIGHT);
		bb.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent evt) {
				Display.getInstance().execute(tt1.getText());
			}
		});
		
		
		this.addComponent(bb);
		
		this.addComponent(new Label("Platform = "+ Display.getInstance().getPlatformName()));
		if (Display.getInstance().isPortrait())	this.addComponent(new Label("Orientation = Portrait"));
		if (!Display.getInstance().isPortrait()) this.addComponent(new Label("Orientation = Paysage"));
		this.addComponent(new Label("Resolution = "+Display.getInstance().getDisplayHeight() + "x" + Display.getInstance().getDisplayWidth()));
		this.addComponent(new Label("Nombre couleurs = "+Display.getInstance().numColors()));
		this.addComponent(new Label("Tablette = "+Display.getInstance().isTablet()));
		UIBuilder uu = new UIBuilder();
		this.addComponent(new Label("Back command enable = "+uu.isBackCommandEnabled()));		
		Button ee=new Button("Vider le cache");
		ee.getStyle().setPadding(15, 15, 10, 10);
		ee.setAlignment(Component.RIGHT);
		ee.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent evt) {
				Storage stor=new Storage();
				stor.clearCache();
			}
		});
		this.addComponent(ee);		
		
		ee=new Button("Vider les datas");
		ee.getStyle().setPadding(15, 15, 10, 10);
		ee.setAlignment(Component.RIGHT);
		ee.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent evt) {
				Storage stor=new Storage();
				stor.clearStorage();
			}
		});
		this.addComponent(ee);
		
		ee=new Button("Exit application");
		ee.getStyle().setPadding(15, 15, 10, 10);
		ee.setAlignment(Component.RIGHT);
		ee.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent evt) {
				Display.getInstance().exitApplication();
			}
		});
		this.addComponent(ee);
	}

	public menutab_reglage(Layout layout) {
		super(layout);
		// TODO Auto-generated constructor stub
	}

}
